package com.thiscc.sum.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mongodb.DBObject;
import com.thiscc.sum.logic.WorkLogic;

@Controller
@RequestMapping("/work")
public class WorkController extends CommonController{
	
	private WorkLogic workLogic = new WorkLogic();

	/*-------------------------------------------------------------------------------------------*/
	
	@RequestMapping("getWorkList")
	public void getWorkList(HttpServletRequest request, 
			HttpServletResponse response) {
		
		JSONObject json = workLogic.getWorkList(request);
		send(response, json.toString());
	}
	
	/*------------------------------------------------------------------------------*/
	@RequestMapping("getAllWorkList")
	public void getAllWorkList(HttpServletRequest request, 
			HttpServletResponse response) {
		
		List<DBObject> topList = workLogic.getAllWorkList(request);
		send(response, JSONArray.fromObject(topList).toString());
	}
	
	/*------------------------------------------------------------------------------*/
	@RequestMapping("getShowWorkList")
	public void getShowWorkList(HttpServletRequest request, HttpServletResponse response) {
		
		JSONArray array = this.workLogic.getShowWorkList(request);
		send(response, array.toString());
	}
	
	/*------------------------------------------------------------------------------*/
	/**
	 * 设置工作列表是否显示
	 * @param showList 需要的显示的功能
	 * @param hideList 需要的隐藏的功能
	 * @return
	 */
	@RequestMapping("setShow")
	public void setShow(HttpServletRequest request, HttpServletResponse response){
		
		String flag = this.workLogic.setShow(request);
		send(response, flag);
	}
	
	/*------------------------------------------------------------------------------*/
	/**
	 * 置顶
	 * @return
	 */
	@RequestMapping("setTop")
	public void setTop(HttpServletRequest request, HttpServletResponse response){
		
		String flag = this.workLogic.setTop(request);
		send(response, flag);
	}
	
	/*------------------------------------------------------------------------------*/
	/**
	 * 取消置顶
	 * @return
	 */
	@RequestMapping("setNotTop")
	public void setNotTop(HttpServletRequest request, HttpServletResponse response){
		
		String flag = this.workLogic.setNotTop(request);
		send(response, flag);
	}
	
	/*------------------------------------------------------------------------------*/
	/**
	 * 增加功能消息条数
	 * @return
	 */
	@RequestMapping("addMsgCount")
	public void addMsgCount(HttpServletRequest request, HttpServletResponse response){
		
		String flag = this.workLogic.addMsgCount(request);
		send(response, flag);
	}
	
	/*------------------------------------------------------------------------------*/
	/**
	 * 减少功能消息条数
	 * @return
	 */
	@RequestMapping("reduceMsgCount")
	public void reduceMsgCount(HttpServletRequest request, HttpServletResponse response){
		
		String flag = this.workLogic.reduceMsgCount(request);
		send(response, flag);
	}
	
	/*------------------------------------------------------------------------------*/
	/**
	 * 功能消息条数清零
	 * @return
	 */
	@RequestMapping("deleteMsgCount")
	public void deleteMsgCount(HttpServletRequest request, HttpServletResponse response){
		
		String flag = this.workLogic.deleteMsgCount(request);
		send(response, flag);
	}
	
	/*------------------------------------------------------------------------------*/
	/**
	 * 修改分组的编号
	 * @param request
	 * @param response
	 */
	@RequestMapping("updateGroupId")
	public void updateGroupId(HttpServletRequest request, HttpServletResponse response){
		
		String flag = this.workLogic.updateGroupId(request);
		send(response, flag);
	}
	
	/*------------------------------------------------------------------------------*/
	/**
	 * 删除分组
	 * @param request
	 * @param response
	 */
	@RequestMapping("deleteGroup")
	public void deleteGroup(HttpServletRequest request, HttpServletResponse response){
		
		String flag = this.workLogic.deleteGroup(request);
		send(response, flag);
	}
}
